<template>
    <el-container>
        <el-header>
            <div class="left-panel">
                <!-- <el-button type="primary" icon="el-icon-plus" v-auth="'othershou.add'" @click="add"></el-button>
                <el-button type="danger" plain icon="el-icon-delete" v-auth="'othershou.delete'" :disabled="selection.length == 0" @click="batch_del"></el-button> -->
            </div>
            <div class="right-panel">
                <div class="right-panel-search">
                    <el-input v-model="search.other_code" placeholder="请输入编号" clearable @keyup.enter="upsearch"></el-input>
                    <!-- <el-select v-model="search.customer_id" filterable clearable placeholder="请选择客户">
                        <el-option v-for="item in clientList" :key="item.id" :label="item.customer_name" :value="item.id"/>
                    </el-select> -->
                    <el-select v-model="search.supplier_id" placeholder="请选择供应商" filterable clearable>
                        <el-option v-for="item in applyList" :key="item.apply_id" :label="item.apply_name" :value="item.apply_id"></el-option>
                    </el-select>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                    <el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
                </div>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" row-key="id" :apiObj="apiObj" @selection-change="selectionChange" stripe remoteSort remoteFilter border :params="query">
                <el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
                <el-table-column type="index" label="序号" fixed align="center" width="50"></el-table-column>
                <!-- <el-table-column label="单据编号" prop="purchase.code" align="center"></el-table-column> -->
                <!-- <el-table-column label="发票状态" prop="status" align="center">
                    <template #default="scope">
                        <el-tag :type="scope.row.status == 1 ? 'warning' :  'success'">
                            {{scope.row.status == 1 ? ' 未开票' : '已开票'}}
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="状态" prop="is_cancel" align="center">
                    <template #default="scope">
                        <el-tag :type="scope.row.is_cancel == 1 ? 'warning' :  'success'">
                            {{scope.row.is_cancel == 1 ? ' 已作废' : '正常'}}
                        </el-tag>
                    </template>
                </el-table-column> -->
                <el-table-column label="发票号" prop="invoice_code" align="center"></el-table-column>
                <!-- <el-table-column label="发票备注" prop="remark" align="center"></el-table-column> -->
                <el-table-column label="单据日期" prop="document_date" align="center"></el-table-column>
                <el-table-column label="供应商" prop="supplier.apply_name" align="center"></el-table-column>
                <el-table-column label="总计" prop="total_money" align="center"></el-table-column>
                <el-table-column label="实付" prop="cost_money" align="center"></el-table-column>
                <!-- <el-table-column label="操作" align="center" width="170">
                    <template #default="scope">
                        <el-button-group>
                            <el-button text type="primary" size="small" @click="table_invoice(scope.row, scope.$index)" v-auth="'invoiceprocure.invoice'" v-if="scope.row.status == 1">开票</el-button>
                            <el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)" v-auth="'invoiceprocure.show'" v-if="scope.row.status == 2">查看</el-button>
                        </el-button-group>
                    </template>
                </el-table-column> -->
            </scTable>
        </el-main>
    </el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false"></save-dialog>
</template>

<script>
import saveDialog from './save'

export default {
	name: '客户列表',
	components: {
		saveDialog,
	},
	data() {
		return {
			dialog: {
				save: false,
			},
			apiObj: this.$API.finance.invoice.purchase.list,
			selection: [],
			search: {
				other_code: null,
			},
            clientList: [],
            applyList: [],
		}
	},
    mounted () {
        this.getClient();
        this.getApply()
    },
	methods: {
        //查看
		table_show(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('show').setData(row)
			})
		},
		//编辑
		table_invoice(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        refresh(){
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.$refs.table.upData(this.search)
        },
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		},
        // 客户
        async getClient(){
            var res = await this.$API.client.client.all.get();
            this.clientList = res.data;
        },
        // 供应商
        async getApply(){
            var res = await this.$API.apply.apply.all.get();
            this.applyList = res.data;
        },
	}
}
</script>

<style></style>
